package com.ship.common.core.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author 31463
 */
@Component
public class SpringUtil implements ApplicationContextAware {

	private ApplicationContext applicationContext;
	
	public Object getBean(String name) {
		return applicationContext.getBean(name);
	}

	public Object getBean(Class<?> c) {
		return applicationContext.getBean(c);
	}
	
	public <T> Map<String, T> getBeansOfType(Class<T> c) {
		return applicationContext.getBeansOfType(c);
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.applicationContext = applicationContext;
	}
}
